package com.deer.wms.base.system.web.item;

import com.deer.wms.base.system.model.item.ItemSpecification;
import com.deer.wms.base.system.service.item.ItemSpecificationService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 物料类型，包装规格
 */
@Controller
@RequestMapping("ItemSpecification")
public class ItemSpecificationController extends BaseController {
    @Autowired
    private ItemSpecificationService itemSpecificationService;
    private String prefix = "system/itemSpecification";
    /**
     * 页面查询包装列表
     */
    @RequiresPermissions("system:Specification:list")
    @PostMapping("/findList")
    @ResponseBody
    public TableDataInfo findList(ItemSpecification itemSpecification)
    {
        startPage();
        List<ItemSpecification> list = itemSpecificationService.findItemSpecificationList(itemSpecification);

        return getDataTable(list);
    }

    /**
     * 下拉框显示规格
     * @return
     */
    @PostMapping("/specList")
    @ResponseBody
    public List<ItemSpecification> ItemSpecificationList(){
        return itemSpecificationService.ItemSpecificationList();
    }

    /**
     *下拉框显示数量
     * @param itemSpec
     * @return
     */
    @PostMapping("/quantityList")
    @ResponseBody
    public List<ItemSpecification> findItemSpecificationByItemSpec(String itemSpec){
        return itemSpecificationService.findItemSpecificationByItemSpec(itemSpec);
    }

    /**
     * 删除包装规格
     */
    @RequiresPermissions("system:Specification:remove")
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        return toAjax(itemSpecificationService.delectItemSpecificationByIds(ids));
    }

    /**
     * 跳转主页面
     * @return
     */
    @RequiresPermissions("system:Specification:view")
    @GetMapping("/page")
    public String itemInfo()
    {
        return prefix + "/itemSpecification";
    }

    /**
     * 新增跳转
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存
     */
    @RequiresPermissions("system:Specification:add")
    @PostMapping("/insert")
    @ResponseBody
    public AjaxResult addSave(ItemSpecification itemSpecification){
        return toAjax( itemSpecificationService.saveItemSpecification(itemSpecification));
    }
    /**
     * 修改跳转
     */
    @GetMapping("/edit/{itemSpecificationId}")
    public String edit(@PathVariable("itemSpecificationId") Integer itemSpecificationId, ModelMap mmap)
    {
        ItemSpecification itemSpecification= itemSpecificationService.findItemSpecificationById(itemSpecificationId);
        mmap.put("itemSpecification", itemSpecification);
        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    @RequiresPermissions("system:Specification:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult update(ItemSpecification itemSpecification){
        return toAjax( itemSpecificationService.updateItemSpecification(itemSpecification));
    }

}
